#ifndef __MCS__BLOCK_PROCESSOR__HPP
#define __MCS__BLOCK_PROCESSOR__HPP

#include "String.hpp"
#include "SourceLocation.hpp"

class InputStream;

/// Parses blocks of text and script code
class Preprocessor
{
public:
	Preprocessor(InputStream * stream);
	~Preprocessor();
	
	int read(char * data, int maxCount);
	std::pair<String,SourceLocation> takeTextBlock();
	SourcePosition takePosition();
private:
	enum State
	{
		UnitializedText,
		Text,
		AtSign,
		UninitializedCodeBlock,
		InLineCodeBlock,
		EndOfLineCodeBlock,
		MultiLineCodeBlock,
		MaybeEndOfBlock,
		EndOfLineComment,
		MultiLineComment,
		MaybeEndOfComment,
		EndOfFile,
	};

	InputStream * stream_;
	std::vector<char> outBuffer_;
	State state_;
	State codeBlockState_;
	std::deque< std::pair<String, SourceLocation> > textBlocks_;
	std::deque< SourcePosition > positions_;
};

#endif //__MCS__BLOCK_PROCESSOR__HPP
